package com.dhy.controller;

import com.dhy.msg.CommonResult;
import com.dhy.pojo.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class PayController
{
    @Value("${server.port}")
    private String server_port;
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        // 业务逻辑处理正确，但是需要耗费3秒钟
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(id==1)
        {
            return new CommonResult(200,"恭喜您查询成功,当前端口号为:"+server_port);
        }else{
            return new CommonResult(444,"没有对应记录,查询ID: "+id,null);
        }
    }

    @GetMapping("/payment/lb/{id}")
    public CommonResult<Payment> getPayIb(@PathVariable("id")Integer id)
    {
        return new CommonResult<>(200,"(*^▽^*)"+"    当前端口号:"+server_port);
    }
    @GetMapping("/payment/zipkin")
    public String paymentZipkin() {
        return "hi ,i'am paymentzipkin server fall back，welcome to here, O(∩_∩)O哈哈~";
    }
}
